package org.dromara.web.controller.business;

import cn.dev33.satoken.annotation.SaIgnore;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.dao.business.domain.Settings;
import org.dromara.web.controller.business.req.SettingReq;
import org.dromara.web.service.business.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/common/settings")
public class SettingsController extends BaseController {

    @Autowired
    SettingsService settingsService;


    @GetMapping("/list")
    public R<List<Settings>> settings() {

        return R.ok(settingsService.list());
    }

    @Log(title = "参数设置", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R<Void> update(@RequestBody  SettingReq.SettingUpdate req) {
        settingsService.updateSettings(req.getSettings());
        return R.ok();
    }


    @SaIgnore
    @GetMapping("/settings")
    public R<Map<String,String>> settingsMap() {

        return R.ok(settingsService.getSettingsMap());
    }
}
